package com.iyanbao.ui.model;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.iyanbao.BasicAct;
import com.iyanbao.R;
import com.iyanbao.model.Good;
import com.iyanbao.model.IYBCache;
import com.iyanbao.model.Service;
import com.iyanbao.utils.MyUtil;


public class MechineServiceAdapter extends IybBaseAdapter {
	BasicAct mContext;
	String mechineSn;
	LayoutInflater mInflate;
	public MechineServiceAdapter(BasicAct mContext, String sn) {
		super();
		this.mContext = mContext;
		this.mechineSn = sn;
		mInflate = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return queryData().size();
	}

	@Override
	public Service getItem(int position) {
		// TODO Auto-generated method stub
		return queryData().get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		MechineServiceHolder holder;
		if (convertView == null) {
			convertView = mInflate.inflate(
					R.layout.item_repairsevice_repairinfo, null);
			holder = new MechineServiceHolder();
			holder.serviceName = (TextView)convertView.findViewById(R.id.tv_servicename_item_repairservice);
			holder.serviceStatus = (TextView)convertView.findViewById(R.id.tv_status_item_repairservice);
			holder.serviceType = (TextView)convertView.findViewById(R.id.tv_servicetype_item_repairservice);
			
			holder.serviceStartDate = (TextView)convertView.findViewById(R.id.tv_starttime_item_repairservice);
			holder.serviceStartEndDate = (TextView)convertView.findViewById(R.id.tv_endtime_item_repairservice);
			holder.serviceDelivered = (TextView)convertView.findViewById(R.id.tv_deliveredthing_item_repairservice);
			convertView.setTag(holder);
		} else {
			holder = (MechineServiceHolder) convertView.getTag();
		}
		Service s = getItem(position);
		holder.setEntity(s);
		return convertView;
	}

	public ArrayList<Service> queryData() {
		Good g = IYBCache.iybCache.getGood(mechineSn);
		ArrayList<Service> services  = g.services;
		MyUtil.log("services","services::"+services.size());
		return services;
	}
}
